
<!--
 * @Author: [kangjie]
 * @Date: 2022-03-30 10:49:39
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-01 14:33:30
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
  <!-- 混入对象 mixin  -->
  <div id="app">
    {{mixinData}}-{{msg}}-{{obj}}
    <my-a></my-a>
  </div>
  <script>
    // 混入对象
    let mixin={
      data(){
        return {
          // 混入的数据
          mixinData:'混入的数据',
          obj:{name:'张三',age:12}
        }
      },
      // 生命周期
      created(){
        console.log('混入的created')
      },
      methods:{
        mixinMethod(){
          console.log('我是混入的方法');
        },
        test(){
          console.log('111111')
        }
      }
    };
    // 创建一个组件
    let myA={
      data(){
        return {
          obj:{name:'王五',age:15}
        }
      },
      created(){
        console.log('我是a组件');
      },
      template:`
        <div>A组件</div>
      `
    };
    Vue.component('my-a',myA);
    Vue.mixin(mixin);
    let vm=new Vue({
      el:'#app',
      // 局部混入
      // mixins:[mixin],
      data:{
        msg:'我是组件',
        obj:{name:"李四",gender:'男'}
      },
      created(){
        console.log('我是vue的生命周期created');
      },
      methods:{
        test(){
          console.log('test')
        }
      }
    });
  </script>
</body>
</html>